{extend name="$basepop" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>

{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>矿机名称:</dt>
		<dd>
			<input type="text" id="level_name" class="input-common">
			<p class="error">请输入矿机名称</p>
			<p class="hint">设置矿机名称</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>日产量:</dt>
		<dd>
			<input type="number" id="day_product" class="input-common">
			<p class="error">请输入日产量</p>
			<p class="hint">设置日产量</p>
		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>总产量:</dt>
		<dd>
			<input type="number" id="total_product" class="input-common">
			<p class="error">请输入总产量</p>
			<p class="hint">设置总产量</p>
		</dd>
	</dl>
	<dl>
		<dt>矿机图片：</dt>
		<dd>
			<div class="upload-btn-common">
				<div>
					<input class="input-file" name="file_upload" id="uploadImgweb_qrcode" type="file" onchange="imgUpload(this);" title="上传">
					<input type="hidden" id="mill_pic" value="" />
				</div>
				<input type="text" id="text_mill_pic" class="input-common" readonly="readonly" value="" />
				<em>上传</em>

				<img id="preview_web_qrcode" src="__STATIC__/blue/img/upload-common-select.png" data-html="true" data-container="body" data-placement="top" data-trigger="manual"/>

			</div>

			<p class="hint">
				<span>建议使用<i class="important-note">宽100</i>像素-<i class="important-note">高100</i>像素内的<i class="important-note">GIF</i>或<i class="important-note">PNG</i>透明图片</span>
			</p>

		</dd>
	</dl>
	<dl>
		<dt><span class="required">*</span>状态:</dt>
		<dd>
			<input id="status" type="checkbox"  class="checkbox" />
			<p class="hint">设置启用状态</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="addGift();">保存</button>
		</dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>	
     var flag = false;//防止重复提交
	//保存
	function addGift(){
		var level_name = $("#level_name").val();
        var day_product = $("#day_product").val();
        var total_product = $("#total_product").val();
        var status = $("#status").prop('checked') ? 1 : 0 ;
        var mill_pic = $("#mill_pic").val();

		if (level_name == '') {
			$("#level_name").next().show().css("display","inline-block");
			$("#level_name").focus();
			return false;
		} else {
			$(".error").hide();
		}

        if (day_product == '') {
            $("#day_product").next().show().css("display","inline-block");
            $("#day_product").focus();
            return false;
        } else {
            $(".error").hide();
        }
        if (total_product == '') {
            $("#total_product").next().show().css("display","inline-block");
            $("#total_product").focus();
            return false;
        } else {
            $(".error").hide();
        }



        if(flag){
			return false;
		}
		flag = true;
		$.ajax({
			type : "post",
			url : "ADMIN_MAIN/mine/addMill",
			data : {
				'level_name' : level_name,
				'day_product' : day_product,
                'total_product' : total_product,
				'mill_pic' : mill_pic,
                'status' : status
			},
			async : true,
			success : function(data) {
				//alert(JSON.stringify(data));
				if (data["code"] > 0) {
					showMessage('success', data["message"]);
                    setTimeout('parent.close_Layer();parent.location.reload()',2000);
				}else{
					showMessage('error', data["message"]);
				}	
				flag = false;
			}
		});
	}


	 function imgUpload(event) {
		 var fileid = $(event).attr("id");
		 var id = $(event).next().attr("id");
		 var data = { 'file_path' : "config" };
		 uploadFile({
			 url: __URL(ADMINMAIN + '/millLevel/uploadimage'),
			 fileId: fileid,
			 data : data,
			 callBack: function (res) {
				 if(res.code){
					 $("#"+id).val(res.data.path);
					 $("#text_" + id).val(res.data.path);
					 $("#preview_" + id).attr("data-src",__IMG(res.data.path));
					 showTip(res.message,"success");
				 }else{
					 showTip(res.message,"error");
				 }
			 }
		 });
	 }
</script>
{/block}